package own.stu.jobgib.playown.io.simple;

import com.google.common.base.Objects;
import org.apache.commons.lang3.StringUtils;
import own.stu.jobgib.playown.io.common.TSocket;

import java.io.IOException;
import java.util.Scanner;

import static own.stu.jobgib.playown.io.common.SocketOptionTest.Type;

public class SimpleClient {
    public static void main(String[] args) throws IOException {
        TSocket socket = new TSocket("localhost", 9999, Type.FromClient);
//        TSocket socket = new TSocket("localhost", 8888);
        socket.open();
        System.out.println("connect to server");

        Scanner scanner = new Scanner(System.in);
        while (true) {
            String inputStr = scanner.nextLine();
            if (Objects.equal(inputStr, "quit")) {
                break;
            }
            if(StringUtils.isBlank(inputStr)){
                continue;
            }
            try {
                socket.write(inputStr);
                System.out.println(" ============= ");
                System.out.println("reply from server : " + socket.read());
            } catch (Exception e) {
                e.printStackTrace();
            }
        }

        socket.close();

    }

}
